#include "parafluidplane.h"

using namespace ParaFluid;

Plane::~Plane()
{
	/* does nothing */
}

Plane::Plane()
	: Object()
	, normal()
{
	/* does nothing */
}

Plane::Plane(const Vector & pos, const Vector & normal)
	: Object(pos)
	, normal(normal)
{
	/* does nothing */
}

Plane::Plane(const Plane & other)
	: Object(other)
	, normal(other.normal)
{
	/* does nothing */
}

Plane & Plane::operator= (const Plane & rhs)
{
	if(&rhs != this)
	{
		Object::operator=(rhs);
		normal = rhs.normal;
	}
	return *this;
}

bool Plane::operator== (const Plane & rhs) const
{
	bool result = true;
	if(&rhs != this)
	{
		result &= Object::operator==(rhs);
		result &= normal == rhs.normal;
	}
	return result;
}

Vector Plane::projection(const Vector & point) const
{
	Vector N(normal);
	N.unitary();
	
	float length = point.length();
	
	if(length == 0)
	{
		return Vector(0, 0, 0);
	}
	else
	{
		return point - (N * (point * N / (length * length)));
	}
}

